package com.easyedu.core.utils;

import java.util.Calendar;

/**
 * @author lmr
 **/
public class SchoolYearUtil {

    private static final Calendar CALENDAR = Calendar.getInstance();


    public static String getSemester() {
        int month = getMonth();
        if ((month >= 9 && month <= 12) || (month <= 1)) {
            return "第一学期";
        } else {
            return "第二学期";
        }
    }

    public static int getOneGradeComeSchoolYear() {
        int year = getYear();
        String semester = getSemester();
        if (semester.equals("第一学期")) {
            return year;
        }
        return year - 1;
    }

    public static int getTwoGradeComeSchoolYear() {
        int year = getYear();
        String semester = getSemester();
        if (semester.equals("第一学期")) {
            return year - 1;
        }
        return year - 2;
    }

    public static int getThreeGradeComeSchoolYear() {
        int year = getYear();
        String semester = getSemester();
        if (semester.equals("第一学期")) {
            return year - 2;
        }
        return year - 3;
    }

    public static int getFourGradeComeSchoolYear() {
        int year = getYear();
        String semester = getSemester();
        if (semester.equals("第一学期")) {
            return year - 3;
        }
        return year - 4;
    }

    private static int getYear() {
        return CALENDAR.get(Calendar.YEAR);
    }

    private static int getMonth() {
        return CALENDAR.get(Calendar.MONTH);
    }

    public static String getStudentGradeByYearAndSemester(int openYear, String semester) throws RuntimeException {
        if (semester.equals("第一学期")) {
            return String.valueOf(openYear);
        } else if (semester.equals("第二学期")) {
            return String.valueOf(openYear - 1);
        } else {
            throw new RuntimeException("年份转换年级出错");
        }
    }
}
